/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.account.Key.DataSourceBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.common.soap.SoapFaultException;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.datasource.DataSourceManager;
/*    */ import com.zimbra.cs.db.DbDataSource;
/*    */ import com.zimbra.cs.db.DbImapFolder;
/*    */ import com.zimbra.cs.db.DbPop3Message;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.type.DataSourceType;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DeleteDataSource
/*    */   extends MailDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException, SoapFaultException
/*    */   {
/* 44 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 45 */     Provisioning prov = Provisioning.getInstance();
/* 46 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 48 */     if (!canModifyOptions(zsc, account)) {
/* 49 */       throw ServiceException.PERM_DENIED("can not modify options");
/*    */     }
/* 51 */     Mailbox mbox = getRequestedMailbox(zsc);
/*    */     
/* 53 */     for (Element eDsrc : request.listElements()) {
/* 54 */       DataSource dsrc = null;
/* 55 */       String id = eDsrc.getAttribute("id", null);
/*    */       
/* 57 */       if (id != null) {
/* 58 */         dsrc = prov.get(account, Key.DataSourceBy.id, id); } else { String name;
/* 59 */         if ((name = eDsrc.getAttribute("name", null)) != null) {
/* 60 */           dsrc = prov.get(account, Key.DataSourceBy.name, name);
/*    */         } else {
/* 62 */           throw ServiceException.INVALID_REQUEST("must specify either 'id' or 'name'", null);
/*    */         }
/*    */       }
/* 65 */       if (dsrc != null)
/*    */       {
/* 67 */         String dataSourceId = dsrc.getId();
/* 68 */         DataSourceType dstype = dsrc.getType();
/*    */         
/* 70 */         prov.deleteDataSource(account, dataSourceId);
/* 71 */         if (dstype == DataSourceType.pop3) {
/* 72 */           DbPop3Message.deleteUids(mbox, dataSourceId);
/* 73 */         } else if (dstype == DataSourceType.imap)
/* 74 */           DbImapFolder.deleteImapData(mbox, dataSourceId);
/* 75 */         DbDataSource.deleteAllMappings(dsrc);
/* 76 */         DataSourceManager.cancelSchedule(account, dataSourceId);
/*    */       }
/*    */     }
/* 79 */     Element response = zsc.createElement(MailConstants.DELETE_DATA_SOURCE_RESPONSE);
/* 80 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/DeleteDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */